package com.xuecheng.manage_cms.controller;

import com.xuecheng.api.cms.CmsPageControllerApi;
import com.xuecheng.framework.domain.cms.CmsPage;
import com.xuecheng.framework.domain.cms.request.QueryPageRequest;
import com.xuecheng.framework.domain.cms.response.CmsPageResult;
import com.xuecheng.framework.domain.course.response.PreviewResult;
import com.xuecheng.framework.domain.course.response.PublishResult;
import com.xuecheng.framework.model.response.CommonCode;
import com.xuecheng.framework.model.response.QueryResponseResult;
import com.xuecheng.framework.model.response.QueryResult;
import com.xuecheng.framework.model.response.ResultCode;
import com.xuecheng.manage_cms.service.CmsPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/cms")
public class CmsPageController implements CmsPageControllerApi {
    @Autowired
    private CmsPageService cmsPageService;

    @GetMapping("/list/{page}/{size}")
    public QueryResponseResult findList(@PathVariable("page") int page, @PathVariable("size") int size, QueryPageRequest q) {

        return cmsPageService.findList(page, size, q);

    }

    @PostMapping("/add")
    @Override
    public CmsPageResult add(@RequestBody CmsPage cmsPage) {

        return cmsPageService.add(cmsPage);
    }

    @PostMapping("/findById/{id}")
    @Override
    public CmsPageResult findById(@PathVariable("id") String id) {
        return cmsPageService.findById(id);
    }

    @Override
    @PutMapping("/update/{id}")
    public CmsPageResult update(@RequestBody CmsPage cmsPage, @PathVariable("id") String id) {
        return cmsPageService.update(id, cmsPage);
    }

    @DeleteMapping("/delete/{id}")
    @Override
    public CmsPageResult delete(@PathVariable("id") String id) {
        return cmsPageService.delete(id);

    }

    /**
     * @Description: 保存页面信息，从课程页面传递cmspage
     * @Param:
     * @return:
     * @Author: Mr.Yuan
     * @Date:
     */

    @PostMapping("/savePageByCourse")
    @Override
    public CmsPageResult savePageByCourse(@RequestBody CmsPage cmsPage) {
        return cmsPageService.savePageByCourse(cmsPage);
    }

    /**
     * @Description: 一键发布
     * @Param: cmspage
     * @return: 发布结果
     * @Author: Mr.Yuan
     * @Date:
     */
    @PostMapping("/onekeypublish")
    @Override
    public PublishResult oneKeyPublish(@RequestBody CmsPage cmsPage) {
        return cmsPageService.oneKeyPublish(cmsPage);
    }
}
